﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Security.Application;

namespace ESAM_Assignment_3
{
    public partial class AddComment : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                tbxComments.Enabled = true;
                tbxSubject.Enabled = true;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string subject = AntiXss.HtmlEncode(tbxSubject.Text);
            string comment = AntiXss.HtmlEncode(tbxComments.Text);
            subject = HtmlEnabler.Enable(subject);
            comment = HtmlEnabler.Enable(comment);
            //string username = HttpUtility.UrlDecode(Request.QueryString["Username"]);
            string username = User.Identity.Name;
            string datePosted = Common.InsertTodayIntoCommentsDate();
            bool status = CommentClass.InsertComment(comment, username, datePosted, subject);

            if (status)
            {
                lblStatus.Text = "Comment added successfully.";
                lblStatus.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblStatus.Text = "An error was encountered, we apologize for the inconvenience. Your comment was not added.";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }

            //Reset the textboxes
            tbxSubject.Text = "";
            tbxComments.Text = "";
        }
    }
}
